<?php

    class Articlem extends CI_Model{

        function __construct(){
            parent::__construct();
        }

        function list_own($condition=NULL){


            $this->db->select('article.id as article_id'); 
            $this->db->select('article.datepublish as article_datepublish'); 
            $this->db->select('article.datepublishend as article_datepublishend'); 
            $this->db->select('article.datepublishhalf as article_datepublishhalf'); 
            $this->db->select('article.datepublishendhalf as article_datepublishendhalf'); 
            $this->db->select('article.title as article_title'); 
            $this->db->select('article.uptitle as article_uptitle'); 
            $this->db->select('article.intro as article_intro'); 
            $this->db->select('article.text article_text'); 
            $this->db->select('article.status article_status'); 
            $this->db->select('article.priority article_priority'); 
            $this->db->select('article.tags article_tags'); 
            $this->db->select('article.user_id article_user_id'); 
            $this->db->select('article.column_id article_column_id'); 
            $this->db->select('article.subcolumn_id article_subcolumn_id'); 

            $this->db->select('user.firstname as user_fname');
            $this->db->select('user.lastname as user_lname');
            $this->db->select('subcolumn.id as subcolumn_id');
            $this->db->select('subcolumn.name as subcolumn_name');
            $this->db->select('column.id as column_id');
            $this->db->select('column.name as column_name');

            $this->db->from('article', 'articlemedia','media');


            $this->db->join('user', 'user.id = article.user_id', "left");
            $this->db->join('subcolumn', 'subcolumn.id = article.subcolumn_id', "left");
            $this->db->join('column', 'column.id = subcolumn.column_id', "left");

            $this->db->where('article.status !=', -1);

            //echo $this->session->userdata('typeofuser_id')."<br />";
            
            switch ($this->session->userdata('typeofuser_id')){

                case 'JN':   $this->db->where('user_id', $this->session->userdata('id'));  break;
                case 'MP':   $this->db->where('user_id', $this->session->userdata('id'));  break;              
                case 'MP':   $this->db->where('user_id', $this->session->userdata('id'));  break;              

            }



            $this->db->order_by('article.id','desc');

            //$this->db->distinct();  

            $res = $this->db->get()->result_array();

            //echo $this->db->last_query();
            //$this->firephp->fb('last:'.$this->db->last_query()); 

            return $res; 




        }

        function art_id($id){

            $this->db->select('article.id as article_id'); 
            $this->db->select('article.datepublish as article_datepublish'); 
            $this->db->select('article.datepublishend as article_datepublishend'); 
            $this->db->select('article.datepublishhalf as article_datepublishhalf'); 
            $this->db->select('article.datepublishendhalf as article_datepublishendhalf'); 
            $this->db->select('article.title as article_title'); 
            $this->db->select('article.title_home as article_title_home'); 
            $this->db->select('article.uptitle as article_uptitle'); 
            $this->db->select('article.intro as article_intro'); 
            $this->db->select('article.text as article_text'); 
            $this->db->select('article.status as article_status'); 
            $this->db->select('article.priority as article_priority'); 
            $this->db->select('article.tags article_tags'); 
            $this->db->select('article.user_id as article_user_id'); 
            $this->db->select('article.column_id as article_column_id'); 
            $this->db->select('article.subcolumn_id as article_subcolumn_id'); 
            $this->db->select('articlemedia.article_id as articlemedia_article_id'); 
            $this->db->select('articlemedia.media_id as articlemedia_media_id'); 
            $this->db->select('media.id as media_id'); 
            $this->db->select('media.type as media_type'); 
            $this->db->select('media.file as media_filepath'); 

            $this->db->from('article', 'articlemedia','media');

            $this->db->where(array('article.id'=>$id));

            $this->db->join('articlemedia', 'articlemedia.article_id = article.id', "left");
            $this->db->join('media', 'media.id = articlemedia.media_id', "left");

            $this->db->order_by('article.id','desc');

            $res = $this->db->get()->result_array();

            $this->firephp->fb('last:'.$this->db->last_query()); 

            return $res; 

        }

    }

?>
